package top.kpromise.user.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import top.kpromise.user.model.response.UserLoginModel;

@Repository
public interface UserLoginMapper {

    @Select("select userId, enabled, loginValue from user_login where userId = #{userId} " +
            " and loginType = #{loginType} limit 1")
    UserLoginModel findUser(String userId, int loginType);

    @Insert("insert into user_login(userId, loginType, loginValue) values (#{userId}, #{loginType}, #{loginValue})")
    int insert(String userId, int loginType, String loginValue);

    @Delete("delete from user_login where userId = #{userId} and loginType = #{loginType} limit 1")
    String deleteByLoginTypeAndValue(String userId, int loginType);

    @Update("update user_login set enabled = 0 where userId = #{userId} and loginType = #{loginType} limit 1")
    int disableLoginType(String userId, int loginType);

    @Update("update user_login set enabled = 1 where userId = #{userId} and loginType = #{loginType} limit 1")
    int enableLoginType(String userId, int loginType);

    @Update("update user_login set loginValue = #{loginValue} where loginType = #{loginType}" +
            " and userId = #{userId} and enabled = 1 limit 1")
    int updateByUserId(String userId, String loginValue, int loginType);
}
